package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.GmallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class GmallController {
    @Autowired
    GmallService gmallService;

    @RequestMapping("/find1")
    public Object find1(String nowDate){
        List<Map> list = gmallService.find1(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray cateArray = new JSONArray();
        for (Map map : list) {
            cateArray.add(map.get("name"));
        }
        dataObject.put("categories",cateArray);


        JSONArray serArray = new JSONArray();
        JSONObject nameObject = new JSONObject();

        nameObject.put("name","name");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            dataArray.add(map.get("total"));
        }
        nameObject.put("data",dataArray);
        serArray.add(nameObject);
        dataObject.put("series",serArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
}
